package com.amumu.drama.common.constant;

import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

@Getter
public enum PayTypeEnum {
    /* 支付类型 */
    WX_PAY(1, "WX_PAY", "微信支付"),
    ALI_PAY(2, "ALI_PAY", "支付宝支付"),
    UNION_PAY(3, "UNION_PAY", "银联支付"),
    WEIWAN_PAY(4, "WEPLAYER_PAY", "微丸积分"),
    ;

    /** 索引 */
    private static final Map<Integer, PayTypeEnum> KEY_UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), PayTypeEnum::getCode);
    /** 索引 */
    private static final Map<String, PayTypeEnum> URL_UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), PayTypeEnum::getType);
    /** key */
    private Integer code;
    /** code url */
    private String type;
    /** 描述 */
    private String desc;

    PayTypeEnum(int code, String type, String desc) {
        this.code = code;
        this.type = type;
        this.desc = desc;
    }

    public static PayTypeEnum getByKey(Integer key) {
        return KEY_UNINDEX.getOrDefault(key, null);
    }

    public static PayTypeEnum getByCode(String key) {
        return URL_UNINDEX.getOrDefault(key, null);
    }
}
